home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libmpeg_src.lha / video.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-19  |  9.9 KB  |  238 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <stdio.h>
  22. #include "mpeg.h"        /* for typedef's */
  23.  
  24. /* X11/xmd.h correctly defines INT32, etc */
  25. #ifndef XMD_H
  26. typedef int INT32;
  27. typedef short INT16;
  28. typedef char INT8;
  29. #endif
  30. typedef unsigned int UINT32;
  31. typedef unsigned short UINT16;
  32. typedef unsigned char UINT8;
  33.  
  34. /* Define Parsing error codes. */
  35.  
  36. #define SKIP_PICTURE -10
  37. #define SKIP_TO_START_CODE -1
  38. #define PARSE_OK 1
  39.  
  40. /* Define BOOLEAN, TRUE, and FALSE. */
  41.  
  42. #define BOOLEAN int
  43. #define TRUE 1
  44. #define FALSE 0
  45.  
  46. /* Set ring buffer size. */
  47.  
  48. #define RING_BUF_SIZE 5
  49.  
  50. /* Macros for picture code type. */
  51.  
  52. #define I_TYPE 1
  53. #define P_TYPE 2
  54. #define B_TYPE 3
  55.  
  56. /* Start codes. */
  57.  
  58. #define SEQ_END_CODE 0x000001b7
  59. #define SEQ_START_CODE 0x000001b3
  60. #define GOP_START_CODE 0x000001b8
  61. #define PICTURE_START_CODE 0x00000100
  62. #define SLICE_MIN_START_CODE 0x00000101
  63. #define SLICE_MAX_START_CODE 0x000001af
  64. #define EXT_START_CODE 0x000001b5
  65. #define USER_START_CODE 0x000001b2
  66.  
  67. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  68.  
  69. #define MB_QUANTUM 100
  70.  
  71. /* Macros used with macroblock address decoding. */
  72.  
  73. #define MB_STUFFING 34
  74. #define MB_ESCAPE 35
  75.  
  76. /* Lock flags for pict images. */
  77.  
  78. #define DISPLAY_LOCK 0x01
  79. #define PAST_LOCK 0x02
  80. #define FUTURE_LOCK 0x04
  81.  
  82. /* External declaration of row,col to zig zag conversion matrix. */
  83.  
  84. extern int scan[][8];
  85.  
  86. /* Temporary definition of time stamp structure. */
  87.  
  88. typedef int TimeStamp;
  89.  
  90. /* Structure with reconstructed pixel values. */
  91.  
  92. typedef struct pict_image {
  93.   unsigned char *luminance;              /* Luminance plane.   */
  94.   unsigned char *Cr;                     /* Cr plane.          */
  95.   unsigned char *Cb;                     /* Cb plane.          */
  96.   unsigned char *display;                /* Display plane.     */
  97.   int locked;                            /* Lock flag.         */
  98.   TimeStamp show_time;                   /* Presentation time. */
  99. } PictImage;
  100.  
  101. /* Group of pictures structure. */
  102.  
  103. typedef struct GoP {
  104.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  105.   unsigned int tc_hours;                 /* Hour component of time code.   */
  106.   unsigned int tc_minutes;               /* Minute component of time code. */
  107.   unsigned int tc_seconds;               /* Second component of time code. */
  108.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  109.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  110.                         previous group of pictures.    */
  111.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  112.   char *ext_data;                        /* Extension data.                */
  113.   char *user_data;                       /* User data.                     */
  114. } GoP;
  115.  
  116. /* Picture structure. */
  117.  
  118. typedef struct pict {
  119.   unsigned int temp_ref;                 /* Temporal reference.             */
  120.   unsigned int code_type;                /* Frame type: P, B, I             */
  121.   unsigned int vbv_delay;                /* Buffer delay.                   */
  122.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  123.                         pixel values flag.              */
  124.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  125.   unsigned int forw_f;                   /* Used for vector decoding.       */
  126.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  127.                         pixel values flag.              */
  128.   unsigned int back_r_size;              /* Used in decoding.               */
  129.   unsigned int back_f;                   /* Used in decoding.               */
  130.   char *extra_info;                      /* Extra bit picture info.         */
  131.   char *ext_data;                        /* Extension data.                 */
  132.   char *user_data;                       /* User data.                      */
  133. } Pict;
  134.  
  135. /* Slice structure. */
  136.  
  137. typedef struct slice {
  138.   unsigned int vert_pos;                 /* Vertical position of slice. */
  139.   unsigned int quant_scale;              /* Quantization scale.         */
  140.   char *extra_info;                      /* Extra bit slice info.       */
  141. } Slice;
  142.  
  143. /* Macroblock structure. */
  144.  
  145. typedef struct macroblock {
  146.   int mb_address;                        /* Macroblock address.              */
  147.   int past_mb_addr;                      /* Previous mblock address.         */
  148.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  149.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  150.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  151.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  152.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  153.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  154.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  155.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  156.   unsigned int cbp;                      /* Coded block pattern.             */
  157.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  158.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  159.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  160.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  161.   int recon_right_for_prev;              /* Past right forw. vector.         */
  162.   int recon_down_for_prev;               /* Past down forw. vector.          */
  163.   int recon_right_back_prev;             /* Past right back vector.          */
  164.   int recon_down_back_prev;              /* Past down back vector.           */
  165. } Macroblock;
  166.  
  167. /* Block structure. */
  168.  
  169. typedef struct block {
  170.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  171.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  172.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  173.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  174. } Block;
  175.  
  176. /* Video stream structure. */
  177.  
  178. typedef struct vid_stream {
  179.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  180.   unsigned int v_size;                         /* Vert. size in pixels.      */
  181.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  182.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  183.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  184.   unsigned char picture_rate;                  /* Code for picture rate.     */
  185.   unsigned int bit_rate;                       /* Bit rate.                  */
  186.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  187.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  188.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  189.                           intracoded frames.         */
  190.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  191.                           non intracoded frames.     */
  192.   char *ext_data;                              /* Extension data.            */
  193.   char *user_data;                             /* User data.                 */
  194.   GoP group;                                   /* Current group of pict.     */
  195.   Pict picture;                                /* Current picture.           */
  196.   Slice slice;                                 /* Current slice.             */
  197.   Macroblock mblock;                           /* Current macroblock.        */
  198.   Block block;                                 /* Current block.             */
  199.   int state;                                   /* State of decoding.         */
  200.   int bit_offset;                              /* Bit offset in stream.      */
  201.   unsigned int *buffer;                        /* Pointer to next byte in
  202.                           buffer.                    */
  203.   int buf_length;                              /* Length of remaining buffer.*/
  204.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  205.   int max_buf_length;                          /* Max lenght of buffer.      */
  206.   PictImage *past;                             /* Past predictive frame.     */
  207.   PictImage *future;                           /* Future predictive frame.   */
  208.   PictImage *current;                          /* Current frame.             */
  209.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  210. } VidStream;   
  211.  
  212. /* Declaration of global pointer to current video stream. */
  213.  
  214. extern VidStream *curVidStream;
  215.  
  216. /* Dither flags external declaration. */
  217. extern char *ditherFlags;
  218.  
  219.  
  220. /* Definition of Contant integer scale factor. */
  221.  
  222. #define CONST_BITS 13
  223.  
  224. /* Misc DCT definitions */
  225. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  226. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  227.  
  228. #define GLOBAL            /* a function referenced thru EXTERNs */
  229.   
  230. typedef short DCTELEM;
  231. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  232.  
  233.  
  234.  
  235. extern double realTimeStart;
  236. extern int totNumFrames;
  237.  
  238.